package com.dayuanit.dy15.websocket.handler;

import com.baidu.aip.speech.AipSpeech;
import com.baidu.aip.speech.TtsResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class BaiduHandler {

    @Value("${message.baidu.appid}")
    private String APP_ID;

    @Value("${message.baidu.key}")
    private String API_KEY;

    @Value("${message.baidu.secret}")
    private String SECRET_KEY;

    public byte[] baiduVoice(String message) {
        // 初始化一个AipSpeech
        AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        // 调用接口
        TtsResponse res = client.synthesis(message, "zh", 1, null);
        byte[] data = res.getData();
        System.out.println("语音合成的长度：" + data.length);

        return data;
    }

}
